﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KetBanBonPhuong;

public partial class UserControls_CreatePost : System.Web.UI.UserControl
{
    private static int GroupID = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        String StrGroup = Request.QueryString["GroupID"];
        if (String.IsNullOrEmpty(StrGroup))
        {
            Response.Redirect("Errors.aspx");
        }
        if (int.TryParse(StrGroup, out GroupID))
        {
            Response.Redirect("Errors.aspx");
        }
    }
    protected void Button_Click(object sender, EventArgs e)
    {
        Post newPost = new Post();
        bool Success = false;
        newPost.Created_date = DateTime.Now;
        newPost.Modified_date = newPost.Created_date;
        newPost.Text = RadEditorContent.Content;
        newPost.Title = TextBox_Title.Text;
        newPost.Is_shown = true;
        newPost.Group_id = GroupID;
        try
        {
            Post.Insert(newPost);
            Success = true;
        }
        catch (System.Exception)
        {
        	Success = false;
        }

        if (!Success)
        {
            Response.Redirect("Group.aspx?GroupID=" + GroupID.ToString());
        }
        else
        {
            Label_Result.Text = "Không thêm được bài viết.";
        }
    }
}
